//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using OpenLS.Core.Serialization;
using OpenLS.Vml.Serialization;

namespace OpenLS.Vml.Drawing
{
    class ShapeDefaults : IOfficeXmlSerializable
    {
        private Callout callout;
        private Ext? _Ext;
        private int? _spidmax;
        private string _style;
        private bool? _fillAttr;
        private bool? _strokeAttr;
        private string _fillcolor;
        private string _strokecolor;
        private bool? _allowincell;
        private TextBox _textbox;
        private Shadow _shadow;
        private Skew _skew;
        private Extrusion _extrusion;
        private Lock _lock;
        private ColorMru _colormru;
        private ColorMenu _colormenu;
        private Stroke _stroke;
        private Fill _fill;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(VmlConstants.OfficeNamespace + "shapedefaults"))
            {
                _Ext = c.GetOptionalEnum<Ext>(VmlConstants.VmlNamespace + "ext");
                _spidmax = c.GetOptionalInteger("spidmax");
                _style = c.GetOptionalString("style");
                _fillAttr = c.GetOptionalBoolean("fill");
                _fillcolor = c.GetOptionalString("fillcolor");
                _strokeAttr = c.GetOptionalBoolean("stroke");
                _strokecolor = c.GetOptionalString("strokecolor");
                _allowincell = c.GetOptionalBoolean(VmlConstants.OfficeNamespace + "allowincell");
                while (c.ReaderLocalName != null)
                {
                    switch (c.ReaderLocalName)
                    {
                        case "fill":
                            _fill = c.ReadElement<Fill>();
                            break;
                        case "stroke":
                            _stroke = c.ReadElement<Stroke>();
                            break;
                        case "textbox":
                            _textbox = c.ReadElement<TextBox>();
                            break;
                        case "shadow":
                            _shadow = c.ReadElement<Shadow>();
                            break;
                        case "skew":
                            _skew = c.ReadElement<Skew>();
                            break;
                        case "extrusion":
                            _extrusion = c.ReadElement<Extrusion>();
                            break;
                        case "callout":
                            callout = c.ReadElement<Callout>();
                            break;
                        case "lock":
                            _lock = c.ReadElement<Lock>();
                            break;
                        case "colormru":
                            _colormru = c.ReadElement<ColorMru>();
                            break;
                        case "colormenu":
                            _colormenu = c.ReadElement<ColorMenu>();
                            break;
                    }
                }
            }
        }

        public void WriteXml(WriteContext context)
        {
            context.DeclareNamespace(VmlConstants.OfficeNamespace);
            using (var c = context.Write(VmlConstants.OfficeNamespace + "shapedefaults"))
            {
                c.SetOptionalEnum<Ext>(VmlConstants.VmlNamespace + "ext", _Ext);
                c.SetOptionalInteger("spidmax", _spidmax);
                c.SetOptionalString("style", _style);
                c.SetOptionalBoolean("fill", _fillAttr);
                c.SetOptionalString("fillcolor", _fillcolor);
                c.SetOptionalBoolean("stroke", _strokeAttr);
                c.SetOptionalString("strokecolor", _strokecolor);
                c.SetOptionalBoolean(VmlConstants.OfficeNamespace + "allowincell", _allowincell);
                c.WriteOptionalElement(_fill);
                c.WriteOptionalElement(_stroke);
                c.WriteOptionalElement(_textbox);
                c.WriteOptionalElement(_shadow);
                c.WriteOptionalElement(_skew);
                c.WriteOptionalElement(_extrusion);
                c.WriteOptionalElement(callout);
                c.WriteOptionalElement(_lock);
                c.WriteOptionalElement(_colormru);
                c.WriteOptionalElement(_colormenu);
            }
        }
    }
}
